package com.software.car.common.entity_change;

import com.software.car.common.utils.FormChangeUtils;
import com.software.car.entity.po.UserPo;
import com.software.car.entity.pro.ModelOptionPro;
import com.software.car.entity.vo.ModelOptionVo;
import com.software.car.entity.vo.ModelTableOptionVo;
import com.software.car.entity.vo.UserDetailVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 魔法はまだ解けない
 * @Date 2021/3/19
 */
@Mapper
public interface ModelOptionChangeMapper {

    ModelOptionChangeMapper INSTANCE = Mappers.getMapper(ModelOptionChangeMapper.class);


    @Mapping(target = "typeName", expression = "java(changeType(userpo.getType()))")
    @Mapping(target = "stateName", expression = "java(changeState(userpo.getState()))")
    @Mapping(target = "valueTypeName", expression = "java(changeValueType(userpo.getValueType()))")
    @Mapping(target = "optionValuePoList", expression = "java(changeOptions(userpo.getDefaultValues()))")
    ModelOptionVo modelProTOVo(ModelOptionPro userpo);


    @Mapping(target = "typeName", expression = "java(changeType(userpo.getType()))")
    @Mapping(target = "valueTypeName", expression = "java(changeValueType(userpo.getValueType()))")
    @Mapping(target = "stateName", expression = "java(changeState(userpo.getState()))")
    ModelTableOptionVo modelTableOptionProTOVo(ModelOptionPro userpo);


    default String changeType(Integer type) {
        if (type == 1) {
            return "文本";
        }
        if (type == 2) {
            return "单选";
        }
        if (type == 3) {
            return "图片";
        }
        if (type == 4) {
            return "日期";
        }
        if (type == 10) {
            return "列表选项，文本";
        }
        return "未定义";
    }

    default String changeState(Integer state) {
        if (state == 1) {
            return "正常";
        }
        if (state == 2) {
            return "停用";
        }
        return "未定义";
    }

    default String changeValueType(Integer valueType) {
        if (valueType == 1) {
            return "文字";
        }
        if (valueType == 2) {
            return "数字";
        }
        return "未定义";
    }
    default List<String> changeOptions(String defaultValues) {
        return FormChangeUtils.getList(defaultValues);
    }
}
